﻿using NicoView.ViewModel.Message;
using NicoView.ViewModel;

using NicoView.Model.Service.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using NicoView.SingleProcess;
using GalaSoft.MvvmLight.Messaging;

namespace NicoView.View
{
    /// <summary>
    /// NicoCommentArtWriteControl.xaml の相互作用ロジック
    /// </summary>
    public partial class NicoViewCommentArtWriteControl : UserControl
    {
        public NicoViewCommentArtWriteControl()
        {
            InitializeComponent();
        }

        public new NicoViewCommentEditorViewModel DataContext
        {
            get
            {
                return base.DataContext as NicoViewCommentEditorViewModel;
            }

        }

        private void CommentArtEditControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!DataContext.IsInDesignMode)
            {
                Messenger.Default.Register<NicoViewCommentEditorConnectionMessage>(this, (args) =>
                {




                });

                Messenger.Default.Register<NicoCommentReplyRequestMessage>(this, (ex) =>
                {
                    if (this.EditText.Visibility == Visibility.Visible)
                    {
                        this.EditText.Text = ">>" + ex.Comment.DisplayNo + " ";
                        this.EditText.Focus();
                        this.EditText.CaretIndex = this.EditText.Text.Length;

                    }
                    
                });


                Messenger.Default.Register<NicoViewCommentEditResetMessage>(this, (args) =>
                {

                    this.EditText.Text = "";
                });

                using (var mutex = MutexControl.CreateMutex())
                {
                    this.DataContext.Loded();
                }

                
            }

            
        }
    }
}
